import $ from 'jquery'
import {url} from '../../util/config'
import {success} from "../../util/responseStatus";
import {message} from "antd";
import login from "../login";
function getNewLogin(values) {
    return insertModule(values)
}
export default function insertModule(values) {
    console.log("values",values)
    let newDate = {
        MODULE_PARENT_ID:values.moduleParentId,
        MODULE_TYPE:values.moduleType,
        MODULE_NAME:values.moduleName,
        MODULE_DESC:values.moduleDesc,
        LAYOUT_TYPE:values.layoutType,
        LAYOUT_PARAMS:values.layoutParams,
        LAYOUT_AREA:values.layoutArea,
        SORT_NUM:values.sortNum,
        MODULE_CONTENT:values.pageContent
    }
    let token = localStorage.getItem("token")
    let status = null;
    $.ajax({
        async:false,
        headers: {
            'Accept': "application/json",
            'Authorization': token
        },
        url: url.api_url+"Module/SubmitModule",
        type: 'POST',
        contentType:"application/json",
        data: JSON.stringify(newDate),
        success: function (result) {
            if(result.result=="Token過期請重新登錄"){
                login(localStorage.getItem("account"), localStorage.getItem("password"));
                status = getNewLogin(values)
            }else {
                if(result.result=="ok"){
                    status = "ok"
                    message.success("新增成功");
                }else message.error("新增失败")
            }

        },
        error:function (error) {
            status = "error"
            message.error("请求异常")
        }
    })
    return status;
    // let arr=[];
    // arr = JSON.parse(sessionStorage.getItem("getModule"))
    // let item = {
    //     moduleId:1009,
    //     moduleName:values.moduleName,
    //     moduleParentId:store.getState().moduleId,
    //     moduleType:values.moduleType,
    // }
    // arr.push(item)
    // alert(arr.length)
    // sessionStorage.setItem("getModule",JSON.stringify(arr))
}

